#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
from mod_python import util,Session,Cookie
import string
import shutil

import time
import sys
reload(sys)
sys.setdefaultencoding('utf8')

__dir__         = os.path.dirname(__file__)

def delete(req, id):
	sess = Session.Session(req)
	file_path = os.path.join(__dir__, 'tmp/' + str(sess['user_id']) + '/' + str(id))
	if os.path.isfile(file_path):
		os.remove(file_path)
	util.redirect(req, "/index.py")

def as_main(req, id):
	sess = Session.Session(req)
	src_path = os.path.join(__dir__, 'tmp/' + str(sess['user_id']) + '/' + str(id))
	dest_path = os.path.join(__dir__, 'tmp/' + str(sess['user_id']) + '/' + str(0))
	if os.path.isfile(src_path):
		shutil.copy(src_path, dest_path)
	util.redirect(req, "/index.py")
